<?php
class ModelWebIndex extends Model {
	
	public function getSetting($types = "") {
		$sql_limit = "";
		if ($types) {
			$sql_limit = "WHERE type IN({$types})";
		}
		$query = $this->db->query ( "SELECT * FROM web_config {$sql_limit} ORDER BY id" );
		return $query->rows;
	
	}
	
	public function editSetting($data) {
		$this->db->query ( "DELETE FROM web_config" );
		$input = array ();
		foreach ( $data ['shop_reason'] as $v ) {
			$input [] = "('" . $v . "',1)";
		}
		$input [] = "('" . $data ['blog_num'] . "',2)";
		$this->db->query ( "INSERT INTO web_config(content,type)VALUES " . implode ( $input, "," ) );
	
	}
	
	function getBlog() {
		$limits = $this->getSetting ( 2 );
		$limit = $limits [0]['content'];
		$query = $this->db->query ( "SELECT * FROM blog_posts WHERE post_status='publish' ORDER BY id DESC LIMIT {$limit}" );
		return $query->rows;
	}
}